/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package nominalitzacions.persistance;
import nominalitzacions.stubs.Dictionary;
import java.io.*;
import java.util.*;


/**
 *
 * @author sonia.sandalinas
 */
public class FormsDataManager {

     protected File diccionariFile;
       public FormsDataManager(String path) throws IOException {
        diccionariFile = new File(path);
        if (!diccionariFile.exists()) {
                diccionariFile.createNewFile();
        }
       }

      public void writeDiccionari(Dictionary<String> diccionari) throws IOException {


        diccionariFile.delete();

        diccionariFile.createNewFile();

        Iterator it = diccionari.iterator();

        FileWriter flw = new FileWriter(diccionariFile);
        BufferedWriter bw = new BufferedWriter(flw);

        while (it.hasNext() ) {
            String verb = (String)it.next();
            bw.write(verb);
            bw.newLine();
        }
        bw.close();
      }
        
      public Dictionary readDiccionari() throws FileNotFoundException, IOException {
        Scanner sc = new Scanner(diccionariFile);
        Dictionary<String> diccionari = new Dictionary();
        while (sc.hasNextLine() ) {
            diccionari.insertString(sc.nextLine() );
        }
        sc.close();
        return diccionari;
      }
}